import 'package:flutter/material.dart';
import 'package:flutter_swiper/flutter_swiper.dart';

class SwiperPage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _SwiperPageState();
  }
}

class _SwiperPageState extends State<SwiperPage> {
  List<String> banners = [
    'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1597031766101&di=4edc89ebc91b5b38a08327395f53c21d&imgtype=0&src=http%3A%2F%2Fimg3.iqilu.com%2Fdata%2Fattachment%2Fforum%2F201308%2F21%2F191917yresbbyhssbbhhjb.jpg',
    'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1597031766101&di=790cb4ebefb4efa00fdf3d37a71092d5&imgtype=0&src=http%3A%2F%2Fimg.ewebweb.com%2Fuploads%2F20190506%2F13%2F1557121349-oATrxwXZgC.jpg',
    'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1597031766101&di=6dd18d7bb06ca81e01cb82c1a0178357&imgtype=0&src=http%3A%2F%2Fwww.wodejia0.com%2Fimages%2Fobuwgnbonzuxa2ldfzrw63i%2F20090810%2F3114308_003924034_2.jpg',
    'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1597031799615&di=c2cbc296be5fe30157802c5a19aae210&imgtype=0&src=http%3A%2F%2Fimg1.imgtn.bdimg.com%2Fit%2Fu%3D3427169086%2C3097665420%26fm%3D214%26gp%3D0.jpg',
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('swiper'),
      ),
      body: SingleChildScrollView(
        child: _body(),
      ),
    );
  }

  Widget _body() {
    return Column(
      children: [
        Container(
          height: 200,
          child: Swiper(
            itemCount: banners.length,
            scrollDirection: Axis.vertical,
            loop: true,
            autoplay: true,
            duration: 500,
            itemBuilder: (context, index) {
              return Image.network(
                banners[index],
                fit: BoxFit.fill,
              );
            },
            pagination: SwiperPagination(),
            controller: SwiperController(),
            onTap: (index) {},
          ),
        ),
        Swiper(
          itemBuilder: (BuildContext context, int index) {
            return new Image.network(
              banners[index],
              fit: BoxFit.fill,
            );
          },
          itemCount: banners.length,
          itemWidth: double.infinity,
          itemHeight: 200,
          layout: SwiperLayout.TINDER,
        ),
        Container(
          height: 200,
          margin: EdgeInsets.only(top: 5, bottom: 5),
          child: Swiper(
            itemBuilder: (BuildContext context, int index) {
              return new Image.network(
                banners[index],
                fit: BoxFit.fill,
              );
            },
            itemCount: banners.length,
            viewportFraction: 0.7,
            scale: 0.5,
          ),
        ),
        Container(
          height: 200,
          child: Swiper(
            itemBuilder: (BuildContext context, int index) {
              return new Image.network(
                banners[index],
                fit: BoxFit.fill,
              );
            },
            itemCount: banners.length,
            itemWidth: 300.0,
            layout: SwiperLayout.STACK,
          ),
        ),
        Container(
          height: 200,
          margin: EdgeInsets.all(5),
          child: Swiper(
              layout: SwiperLayout.CUSTOM,
              customLayoutOption:
                  new CustomLayoutOption(startIndex: -1, stateCount: 3)
                      .addRotate([-45.0 / 180, 0.0, 45.0 / 180]).addTranslate([
                new Offset(-370.0, -40.0),
                new Offset(0.0, 0.0),
                new Offset(370.0, -40.0)
              ]),
              itemWidth: 300.0,
              itemHeight: 200.0,
              itemBuilder: (context, index) {
                return Image.network(
                  banners[index],
                  fit: BoxFit.fill,
                );
              },
              itemCount: banners.length),
        ),
      ],
    );
  }
}
